home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
music
/
87
/
c
/
numview.doc
< prev
next >
Wrap
Text File
|
1986-12-19
|
4KB
|
62 lines
BARS.C
BARS.TOS
NUMVIEW.C
NUMVIEW.TOS
Have you ever wondered what happened to all
those numbers that disappear from your figure tips and into
the ST's memory? Here's your chance to look at some.
Numview allows you to enter an integer and then puts that
value into the 16,000 words (32,000 bytes) of memory that are
used for the screen display. Each word is 16 bits (a bit is
either one or zero). In high resolution each pixel (short
for 'picture element') is set by a single bit (640X400 pixels
= 16,000 words X 16 bits/word = 32,000 bytes X 8 bits/byte).
If the value of the bit is one you see a black spot and, of
course, you see a white spot if the bit is zero. Each row in
high resolution is 40 words (80 bytes). In medium resolution
the screen memory is the same size, so how do we cram color
information into the same space? The pixels are made larger
in medium resolution so that we have a screen resolution of
640X200 pixels. To find which of the four colors (white,
black, red, green) a pixel has, the hardware looks for 2 bits
of information. These two bits are found in two consecutive
words of screen memory. As an example, let us consider the
very first pixel at the top, left hand side of the medium
resolution screen. The ST looks at the first bit of the first
word in screen memory and the first bit of the second word in
screen memory to determine this pixel's color value. There
are 4 possibilities for the values of these two bits: 0 in
the first word and 0 in the second word ( we will call this
0,0); 0,1; 1,0; and finally 1,1. Since Numview puts the same
number in each word of memory, we will see only 0,0 and 1,1
combinations. It turns out this is normally displayed as
white and black in medium resolution. Similar things happen
in low resolution (320X200 pixels), but now the ST looks at
four consecutive words in screen memory. Thus, the first
pixel can have 16 color values depending on the first bit
values of the first 4 words in memory. Once again, Numview
will show only 0,0,0,0 or 1,1,1,1 since all the words in
memory are the same. And you guessed it, this is normally
shown as black and white even in low resolution.
Try some integer values and you will see them converted
to binary and displayed as stripes on the ST screen.
Negative numbers are also interesting, try -1!
Bars.tos displays 31 different screens sequentially each
with a different integer put in all of screen memory. This
shows the speed of the ST's memory writing.
Source code for both programs is included for those like
myself who are learning C. I am currently using the Alcyon
package. Numview.c shows a work around for the scanf()
function of the Alcyon package. It seems that this function
requires a space to terminate any input to scanf(). This is
hardly standard user-interface friendliness! I have made my
own input routine using Cconrs() and sscanf() so that the
carriage return can be used to terminate user input. I am
sure there is a more concise way to transfer the input buffer
to a buffer usable by sscanf() (such as buffer = &input[2]
maybe), but this is what I got to work first.